//
//  HomeTitleButton.swift
//  HJWeibo
//
//  Created by huangjiong on 16/2/1.
//  Copyright © 2016年 huangjiong. All rights reserved.
//

import UIKit

class HomeTitleButton: UIButton {
    
    
    //重写构造方法
    override init(frame: CGRect) {
        //父类实现
        super.init(frame: frame)
        //在初始化方法中,将一些固定的东西写好
        //标题颜色
        setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: UIControlState.Selected)
        //尺寸自动适应内容
        self.sizeToFit()
        
    }
    //注意:重写UIView的构造方法时,一定要再实现这个方法,切记!!
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //重新布局方法,在此方法中,实现自定义布局
    override func layoutSubviews() {
        //父类实现
        super.layoutSubviews()  
        //让标题偏移到最左边
        titleLabel?.frame.origin.x = 0
        //图片偏移到标题的右边
        imageView?.frame.origin.x = titleLabel!.frame.size.width
        
    }
  
}
